 var consNum=0;var payNum=0;$(document).ready(function(){$("#editadr").click(function(){if($("#ConsStatus").attr("value")==0){$(this).html('[关闭]');$("#ConsigneeBox")[0].className="ABBox BoxAct";$("#Constr").html($("#ConsShow").html());$("#ConsShow").html('<img src="/imgs/indicator_waitanim.gif" border="0" />');editAdinfoResponse();}
else{$(this).html('[修改]');$("#ConsigneeBox")[0].className="ABBox hhr";$("#ConsShow").html($("#Constr").html());$("#Constr").html('');}
});$("#editpay").click(function(){if($("#PayStatus").attr("value")==0){$(this).html('[关闭]');$("#PaymentBox")[0].className="ABBox BoxAct";$("#Paymstr").html($("#PaymShow").html());$("#PaymShow").html('<img src="/imgs/indicator_waitanim.gif" border="0" />');editPaymentResponse();}
else{$(this).html('[修改]');$("#PaymentBox")[0].className="ABBox hhr";$("#PaymShow").html($("#Paymstr").html());$("#Paymstr").html('');}
});$("#editPost").click(function(){if($("#PostStatus").attr("value")==0){$(this).html('[关闭]');$("#PostBox")[0].className="ABBox BoxAct";$("#postscriptInfo").css("display", "none");$("#postscriptTemp").css("display", "block");$("#PostStatus").attr("value", 1);}
else{$(this).html('[修改]');$("#PostBox")[0].className="ABBox hhr";$("#postscriptInfo").css("display", "block");$("#postscriptTemp").css("display", "none");$("#PostStatus").attr("value", 0);}
});$("#editFapiao").click(function(){if($("#FapiaoStatus").attr("value")==0){$(this).html('[关闭]');$("#FapiaoBox")[0].className="ABBox BoxAct";$("#fapiaoInfo").css("display", "none");$("#fapiaoTemp").css("display", "block");$("#FapiaoStatus").attr("value", 1);}
else{$(this).html('[修改]');$("#FapiaoBox")[0].className="ABBox hhr";$("#fapiaoInfo").css("display", "block");$("#fapiaoTemp").css("display", "none");$("#FapiaoStatus").attr("value", 0);}
});$("#DTicketTitle").click(function(){if($("input[name=DTicketing]").attr("value")==0){$(this)[0].className="TLTitle on";$("#DTicketList").slideToggle("slow");$("input[name=DTicketing]").attr("value", 1);if($("input[name=HLTicketing]").attr("value")==1){$("#HLTicketTitle")[0].className="TLTitle off";$("#HLTicketList").slideToggle("slow");$("input[name=HLTicketing]").attr("value", 0);}
}
else{$(this)[0].className="TLTitle off";$("#DTicketList").slideToggle("slow");$("input[name=DTicketing]").attr("value", 0);}
});$("#HLTicketTitle").click(function(){if($("input[name=HLTicketing]").attr("value")==0){$(this)[0].className="TLTitle on";$("#HLTicketList").slideToggle("slow");$("input[name=HLTicketing]").attr("value", 1);if($("input[name=DTicketing]").attr("value")==1){$("#DTicketTitle")[0].className="TLTitle off";$("#DTicketList").slideToggle("slow");$("input[name=DTicketing]").attr("value", 0);}
}
else{$(this)[0].className="TLTitle off";$("#HLTicketList").slideToggle("slow");$("input[name=HLTicketing]").attr("value", 0);}
});ConsiShipping();$("input[name=DTicketing]").attr("value", 0);$("input[name=HLTicketing]").attr("value", 0);});function editAdinfoResponse(){$.ajax({url: 'flow.php?step=edit_adinfo&d=' + Math.random(),
type: 'GET',
dataType: 'text',
timeout: 5000,
error: function(){if (consNum >= 2){alert('对不起，网络错误，请重试');}else{editAdinfoResponse();}
consNum++;},
success: function(result){$("#ConsShow").html(result);}
});}
function editPaymentResponse(){$.ajax({url: 'flow.php?step=edit_payment',
type: 'GET',
dataType: 'text',
timeout: 5000,
error: function(){if (payNum >= 2){alert('对不起，网络错误，请重试');}else{editPaymentResponse();}
payNum++;},
success: function(result){$("#PaymShow").html(result);var el=document.forms['checkout'].elements;var len=el.length;var userPayment=document.getElementById('userPayment').value;var userShipping=document.getElementById('userShipping').value;var userBchange=document.getElementById('userBchange').value;for(var i=0; i<len; i++)
{if((el[i].type=="radio") && (el[i].name=='payment') && (el[i].value.toUpperCase()== userPayment.toUpperCase())){el[i].checked=true;selectPayment(el[i], userShipping);}
else if(el[i].value==userBchange){el[i].checked=true;}
}
}
});}
function EditThis(a_id){$("#ConsInfo"+a_id).attr("checked",true);$("#ConsigneeInput").css("display", "block");document.getElementById('address_id_0').value= a_id;ClearMsg();_consignee=document.getElementById('consignee'+a_id);_province=document.getElementById('province'+a_id);_city=document.getElementById('city'+a_id);_district=document.getElementById('district'+a_id);_address=document.getElementById('address'+a_id);_zipcode=document.getElementById('zipcode'+a_id);_tel=document.getElementById('tel'+a_id);_mobile=document.getElementById('mobile'+a_id);document.getElementById("consignee_0").value=_consignee.value;document.getElementById("selProvinces_0").value=_province.value;new_loadRegions({id:'selProvinces_0'},_province.value, 2, 'selCities_0',_city.value,1);new_loadRegions({id:'selCities_0'},_city.value, 3, 'selDistricts_0',_district.value,1);document.getElementById("address_0").value=_address.value;document.getElementById("zipcode_0").value=_zipcode.value;document.getElementById("tel_0").value=_tel.value;document.getElementById("mobile_0").value=_mobile.value;}
function infoin(i_id){$("#ConsigneeInput").css("display", "none");document.getElementById('address_id_0').value= 0;ClearMsg();}
function infono(){$("#ConsigneeInput").css("display", "block");document.getElementById('address_id_0').value= 0;document.getElementById("consignee_0").value='';document.getElementById("selProvinces_0").value=0;document.getElementById("selCities_0").value=0;document.getElementById("selDistricts_0").value=0;document.getElementById("address_0").value='';document.getElementById("zipcode_0").value='';document.getElementById("tel_0").value='';document.getElementById("mobile_0").value='';regionText();ClearMsg();}
function regionText(){selProvince=document.getElementById("selProvinces_0");selCity=document.getElementById("selCities_0");selDistricts=document.getElementById("selDistricts_0");if (selProvince.options[selProvince.selectedIndex].value > 0){document.getElementById("ShowProv").innerHTML=selProvince.options[selProvince.selectedIndex].text+'&nbsp;&nbsp;';if(selCity.options[selCity.selectedIndex].value > 0){document.getElementById("ShowCity").innerHTML=selCity.options[selCity.selectedIndex].text+'&nbsp;&nbsp;';if(selDistricts.options[selDistricts.selectedIndex].value > 0){document.getElementById("ShowDist").innerHTML=selDistricts.options[selDistricts.selectedIndex].text+'&nbsp;&nbsp;';}
else{document.getElementById("ShowDist").innerHTML='';}
}
else{document.getElementById("ShowCity").innerHTML='';document.getElementById("ShowDist").innerHTML='';}
}
else{document.getElementById("ShowProv").innerHTML='';document.getElementById("ShowCity").innerHTML='';document.getElementById("ShowDist").innerHTML='';}
}
function SaveConsignee(){var ConsiFrom=document.forms['ConsiFrom'];var csel=ConsiFrom.elements['ConsInfo'];for(var i=0;i<csel.length;i++){if(ConsiFrom.elements['ConsInfo'][i].checked){cValue=ConsiFrom.elements['ConsInfo'][i].value;break;}
}
address_id=ConsiFrom.elements['address_id_0'].value;if (cValue > 0 && address_id==0){var addre={"type":"select", "ConsInfo": cValue};}
else if(cValue > 0 && address_id==cValue){if (CheckInput()){var addre={"type":"edit", "ConsInfo":cValue, "address_id_0":address_id, 
"consignee":$("#consignee_0").attr("value"), "province":$("#selProvinces_0").attr("value"), "city":$("#selCities_0").attr("value"), "district":$("#selDistricts_0").attr("value"),"address":$("#address_0").attr("value"), "zipcode":$("#zipcode_0").attr("value"), "mobile":$("#mobile_0").attr("value"), "tel":$("#tel_0").attr("value"),"email":$("#email_0").attr("value")};}else{return false;}
}
else if(cValue==0 && address_id==0){if (CheckInput()){var addre={"type":"add", "ConsInfo":cValue, "address_id_0":address_id, "consignee":$("#consignee_0").attr("value"), "province":$("#selProvinces_0").attr("value"), "city":$("#selCities_0").attr("value"), "district":$("#selDistricts_0").attr("value"),"address":$("#address_0").attr("value"), "zipcode":$("#zipcode_0").attr("value"), "mobile":$("#mobile_0").attr("value"), "tel":$("#tel_0").attr("value"),"email":$("#email_0").attr("value")};}else{return false;}
}

$.ajax({url: 'flow.php?step=save_adinfo',
type: "POST",
dataType: 'text',
cache:false,
data: addre,
timeout: 5000,
contentType: "application/x-www-form-urlencoded; charset=utf-8",
error: function(){alert('对不起，网络错误，请重试');},
success: function(result){$("#editadr").html('[修改]');$("#ConsigneeBox")[0].className="ABBox hhr";$("#ConsShow").html(result);$("#Constr").html('');ConsiShipping();}
});}
function SavePayment(){if($("#ConsStatus").attr("value")==1){alert('请先填写收货人信息 并点击上方“确认收货信息”按钮！');$("html,body").animate({scrollTop: $("#ConsigneeBox").offset().top}, 500);return false;}
var frm=document.forms['checkout'];var paymentSelected=false;var shippingSelected=false;var sValue=0;var pValue=0;var BcValue=0; for (i=0; i < frm.elements.length; i ++ ) {if (frm.elements[i].name=='shipping' && frm.elements[i].checked)
{ shippingSelected=true; sValue=frm.elements[i].value;}
if (frm.elements[i].name=='payment' && frm.elements[i].checked)
{ paymentSelected=true; pValue=frm.elements[i].value;if (frm.elements[i].value==2){var selectedBC=-1;for (a=0; a<frm.elements.length; a++){if (frm.elements[a].name=='bchange' && frm.elements[a].checked)
{selectedBC=a;BcValue=frm.elements[a].value;}
}
if (selectedBC<0){alert("您还没有选择要转帐到的银行！");return false;}
}
else if (frm.elements[i].value==6){var selectedBC=-1;for (a=0; a<frm.elements.length; a++){if (frm.elements[a].name=='olpay' && frm.elements[a].checked)
{selectedBC=a;BcValue=frm.elements[a].value;}
}
if (selectedBC<0){alert("您还没有选择网上银行付款所使用的银行！");return false;}
}
} } if (!paymentSelected) {alert('您还没有选择支付方式');return false; } if (!shippingSelected) {if(document.getElementById("nocod") && document.getElementById("nocod").value==1){alert('您所在的地区暂时不支持货到付款，请选择其它支付方式！');return false;}else{alert('您还没有选择配送方式');return false;} }
$.ajax({url: 'flow.php?step=save_payment&shipping='+sValue+'&payment='+pValue+'&payBank='+ BcValue,
type: 'GET',
dataType: 'text',
timeout: 5000,
error: function(){alert('对不起，网络错误，请重试');},
success: function(result){$("#editpay").html('[修改]');$("#PaymentBox")[0].className="ABBox hhr";$("#PaymShow").html(result);$("#Paymstr").html('');countTotal();}
});
$.ajax({url:'flow.php?'})

}
function SavePost(){$("#editPost").html('[修改]');$("#PostBox")[0].className="ABBox hhr";$("#postscriptInfo").css("display", "block");$("#postscriptTemp").css("display", "none");$("#PostStatus").attr("value", 0);$("#postscriptInfo").html($("#postscript").attr("value"));}
function SaveFapiao(){if($("#inv_payee").attr("value") != ''){$("#editFapiao").html('[修改]');$("#FapiaoBox")[0].className="ABBox hhr";$("#fapiaoInfo").css("display", "block");$("#fapiaoTemp").css("display", "none");$("#FapiaoStatus").attr("value", 0);invContent=document.getElementById("inv_content");if (invContent.options[invContent.selectedIndex].text=='不开发票'){$("#fapiaoInfo").html('<font color="#999999">不开发票</font>');$("#fapiao").attr("value", 0);}else{$("#fapiaoInfo").html('发票抬头：' + $("#inv_payee").attr("value") + '&nbsp;&nbsp;内容：' + invContent.options[invContent.selectedIndex].text);$("#fapiao").attr("value", 1);}
}
else{alert('发票内容不能为空');}
}
 
function CheckInput(){isempty=0;var ConsiFrom=document.forms['ConsiFrom'];
var pp = new RegExp(/^1(3|5|8){1}\d{9}$/);
if($("#email_msg").text().length > 6){isempty++;}else{$("#email_msg").html('');};
if($("#consignee_0").attr("value")==''){$("#consignee_msg").html('&nbsp;请填写收货人姓名');isempty++;}else{$("#consignee_msg").html('');}
if($("#selProvinces_0").attr("value")==0 || $("#selCities_0").attr("value")==0 || $("#selDistricts_0").attr("value")==0){$("#region_msg").html('&nbsp;请选择所在地区');isempty++;}else{$("#region_msg").html('');}
if($("#address_0").attr("value")==''){$("#district_msg").html('&nbsp;请填写收货地址');isempty++;}else{$("#district_msg").html('');}
if($("#mobile_0").attr("value")=='' && $("#tel_0").attr("value")==''){$("#mobile_msg").html('&nbsp;手机与电话请至少填写一项');isempty++;}else if (!pp.test($("#mobile_0").val()))
{$("#mobile_msg").html('&nbsp;手机号的格式不正确');isempty++;
}else{$("#mobile_msg").html('');}
if(isempty > 0){return false;}else{return true;}
}
function CheckEmail(){
	var pattern=new RegExp("[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?");	
	if($("#email_0").attr("value")==''){
		$("#email_msg").html('&nbsp;请填写邮箱');isempty++;}else if(!pattern.test($("#email_0").val()))
	{
		$("#email_msg").html('&nbsp;邮箱格式不正确');isempty++;
}else{	
		$.ajax({url: 'flow.php?step=is_registered&email='+$("#email_0").attr("value"),
type: 'GET',
dataType: 'text',
timeout: 5000,
error: function(){alert('对不起，网络错误，请重试');},
success: function(result){$("#email_msg").html(result);}
});
}
if(isempty > 0){return false;}else{return true;}
}

function ClearMsg(){$("#consignee_msg").html('');$("#region_msg").html('');$("#district_msg").html('');$("#mobile_msg").html('');}
function cancle_check(obj)
{$(".PayInfo").css("display", "none");}
function checkselect()
{if($("#ConsStatus").attr("value")==1){alert('请先填写收货人信息 并点击上方“确认收货信息”按钮！');$("html,body").animate({scrollTop: $("#ConsigneeBox").offset().top}, 500);$("input[name=payment]").attr("checked", false);$("#shippingList").html("<span style=\"color=#666666;padding-left:30px;\">请选择支付方式</span>");return false;}
else{return true;}
}
function selectPayment(obj)
{cancle_check(obj);$("#shippingList").html('<img src="/imgs/indicator_waitanim.gif" border="0" />');var nid=$(obj).attr('nid');$(obj).parent().children(".PayInfo").css("display", "block");var iscod=$(obj).attr('isCod');flowType=document.getElementById("flowType").value;flowTypeId=document.getElementById("flowTypeId").value;flowGoodsPrice=document.getElementById("flowGoodsPrice").value;$.ajax({url: 'flow.php?new=1&step=show_shipping&iscod=' + iscod + '&flowType=' + flowType + '&flowTypeId=' + flowTypeId + '&flowGoodsPrice=' + flowGoodsPrice + '&d=' + Math.random(),
type: 'GET',
dataType: 'text',
timeout: 5000,
error: function(){alert('对不起，网络错误，请重试');},
success: function(result){$("#shippingList").html(result);}
});}
function shippingFeeResponse(){$.ajax({url: 'flow.php?step=shippingFeeCounting&goodsprice='+parseInt($("#goodsCount").attr("value"))+'&needtominus='+parseInt($("#ticketCount").attr("value")),
type: 'GET',
dataType: 'text',
timeout: 5000,
error: function(){alert('对不起，网络错误，请重试');},
success: function(result){var frm=document.forms['checkout'];frm.elements['shippingCount'].value=result;$("#shippingFee").html(result);}
});}
function countTotal(){shippingFeeResponse();setTimeout(function(){var frm=document.forms['checkout'];var ttFee=parseInt(frm.elements['goodsCount'].value) + parseInt(frm.elements['shippingCount'].value) - parseInt(frm.elements['ticketCount'].value);ttFee=ttFee < parseInt(frm.elements['shippingCount'].value) ? parseInt(frm.elements['shippingCount'].value) : ttFee;$(".TotalCharge").children("strong").html('￥'+ ttFee +'元');}, 1000);}
function ConsiShipping(){$.ajax({url: 'flow.php?step=ConsiAndShipping',
type: 'GET',
dataType: 'text',
timeout: 5000,
error: function(){alert('对不起，网络错误，请重试');},
success: function(result){if(result=='0' && $("#PayStatus").attr("value")==0){$("#editpay").html('');$("#PaymentBox")[0].className="ABBox BoxAct";$("#Paymstr").html($("#PaymShow").html());$("#PaymShow").html('<img src="/imgs/indicator_waitanim.gif" border="0" />');editPaymentResponse();}
}
});}
function UserDTickets(){var dValue=0;var dIds='';var frm=document.forms['checkout'];var dcheck=frm.elements['Dbonus'];for(i=0;i<dcheck.length;i++){if(frm.elements['Dbonus'][i].checked){dValue += parseInt(frm.elements['Dbonus'][i].attributes['amount'].value);dIds += frm.elements['Dbonus'][i].value +',';}
}
if(frm.elements['HLbonus']){var tdcheck=frm.elements['HLbonus'];for(i=0;i<tdcheck.length;i++){if(frm.elements['HLbonus'][i].checked){frm.elements['HLbonus'][i].checked=false;}
}
}
if(dValue > 0){$("input[name=dseries]").attr("value", dIds)
$("#DTicUsed").html('已使用：'+ dValue +'元');$("#DTicketTitle")[0].className="TLTitle off";$("#DTicketList").slideToggle("slow");$("input[name=DTicketing]").attr("value", 0);$("#TicketFee").html(dValue);$("#canlD").css("display", "");$("input[name=ticketCount]").attr("value", dValue);countTotal();$("input[name=hlseries]").attr("value", '')
$("#HLTicUsed").html('');$("#canlHL").css("display", "none");}
else{$("#canlD").css("display", "none");$("input[name=dseries]").attr("value", '')
$("#DTicUsed").html('');}
}
function UserHLTickets(){var dValue=0;var dIds='';var frm=document.forms['checkout'];var dcheck=frm.elements['HLbonus'];for(i=0;i<dcheck.length;i++){if(frm.elements['HLbonus'][i].checked){dValue=parseInt(frm.elements['HLbonus'][i].attributes['amount'].value);dIds=frm.elements['HLbonus'][i].value;}
}
if(frm.elements['Dbonus']){var tdcheck=frm.elements['Dbonus'];for(i=0;i<tdcheck.length;i++){if(frm.elements['Dbonus'][i].checked){frm.elements['Dbonus'][i].checked=false;}
}
}
if(dValue > 0){$("input[name=hlseries]").attr("value", dIds)
$("#HLTicUsed").html('已使用：'+ dValue +'元');$("#HLTicketTitle")[0].className="TLTitle off";$("#HLTicketList").slideToggle("slow");$("input[name=HLTicketing]").attr("value", 0);$("#TicketFee").html(dValue);$("#canlHL").css("display", "");$("input[name=ticketCount]").attr("value", dValue);countTotal();$("input[name=dseries]").attr("value", '')
$("#DTicUsed").html('');$("#canlD").css("display", "none");}
else{$("#canlHL").css("display", "none");$("input[name=hlseries]").attr("value", '')
$("#HLTicUsed").html('');}
}
function cancleTic(type){if(type=='d'){$("input[name=dseries]").attr("value", '')
$("#DTicUsed").html('');$("#canlD").css("display", "none");var frm=document.forms['checkout'];dcheck=frm.elements['Dbonus'];for(i=0;i<dcheck.length;i++){if(frm.elements['Dbonus'][i].checked){frm.elements['Dbonus'][i].checked=false;}
}
}else if(type=='hl'){$("input[name=hlseries]").attr("value", '')
$("#HLTicUsed").html('');$("#canlHL").css("display", "none");var frm=document.forms['checkout'];dcheck=frm.elements['HLbonus'];for(i=0;i<dcheck.length;i++){if(frm.elements['HLbonus'][i].checked){frm.elements['HLbonus'][i].checked=false;}
}
}
$("#TicketFee").html("0");$("input[name=ticketCount]").attr("value", 0);countTotal();}
function checkPage(){if($("#ConsStatus").attr("value")==1){alert('请先填写收货人信息 并点击上方“确认收货信息”按钮！');$("html,body").animate({scrollTop: $("#ConsigneeBox").offset().top}, 500);return false;}
if($("#PayStatus").attr("value")==1){alert('请先填写支付及配送信息 并点击上方“确认支付及配送信息”按钮！');$("html,body").animate({scrollTop: $("#PaymentBox").offset().top}, 500);return false;}
}

//标签切换zjj
$(function(){
   var $div_li =$("div.in_t ul li");
   $div_li.mouseover(function(){

$(this).addClass("in_boxhover")            //当前<li>元素高亮
  .siblings().removeClass("in_boxhover");  //去掉其它同辈<li>元素的高亮
            var index =  $div_li.index(this);  // 获取当前点击的<li>元素 在 全部li元素中的索引。

$("div.in_b > div")   //选取子节点。不选取子节点的话，会引起错误。如果里面还有div
.eq(index).show()   //显示 <li>元素对应的<div>元素
.siblings().hide(); //隐藏其它几个同辈的<div>元素
})
})
